package DataStructureAndAlgorithm.LeetCode.贪心;

//双指针，pre指针，向前移动，找出差相等的相邻两项
//pre - cur + 1 == 等差数列中数的个数

//链接：https://leetcode-cn.com/problems/arithmetic-slices/

public class ArithmeticSlices {
    public int numberOfArithmeticSlices(int[] nums) {
        if (nums.length < 3)return 0;
        int res = 0;

        for (int i = 0; i < nums.length - 2; i++){
            int j = i + 1;
            int ca = nums[j] - nums[i];
            while (j < nums.length && nums[j] - nums[j - 1] == ca){
                if (j - i >= 2)res++;
                j++;
            }
        }
        return res;
    }
}
